/* Copyright 2017 The Apollo Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#ifndef MODULES_MAP_HDMAP_ADAPTER_ODR_ADAPTER_H_
#define MODULES_MAP_HDMAP_ADAPTER_ODR_ADAPTER_H_

#include <fstream>
#include <iostream>
#include <string>

#include "modules/map/hdmap/adapter/odr_parser/data_define.h"

#include "modules/map/proto/map.pb.h"

#include "modules/map/hdmap/adapter/xml_parser/common_define.h"
#include "modules/map/hdmap/adapter/odr_parser/header_odr_parser.h"
#include "modules/map/hdmap/adapter/odr_parser/junctions_odr_parser.h"
#include "modules/map/hdmap/adapter/odr_parser/lanes_odr_parser.h"
#include "modules/map/hdmap/adapter/odr_parser/objects_odr_parser.h"
#include "modules/map/hdmap/adapter/odr_parser/roads_odr_parser.h"
#include "modules/map/hdmap/adapter/odr_parser/signals_odr_parser.h"

namespace apollo {
namespace hdmap {
namespace adapter {

class OdrAdapter {
 public:
  static bool LoadData(const std::string& filename, apollo::hdmap::Map* pb_map);
 private:
  static void FilleLaneLinkage(OdrMap& map);
  static void ProcessLaneLink(const std::map<std::string, Road*>& roads,
                                 const std::string& fromRoad,
                                 const std::string& fromLane,
                                 const std::string& toRoad,
                                 const std::string& toLane,
                                 const std::string& junctionId,
                                 bool contactStartPoint);
  static Lane* FindLaneInRoad(Road* road, const std::string& laneIdStr, bool startSection);
  static Lane* FindLaneInLaneSection(const LaneSection* section, const std::string& lane_id);
  static void AddLaneLink(Lane* lane, const std::string& roadId,
                             Lane* anotherLane, const std::string& anotherRoadId);
  static Road* FindRoad(const std::map<std::string, Road*>& roads,
                          const std::string& roadId);
  static int check_and_decode(const std::string& infile, std::string& outfile);
};

}  // namespace adapter
}  // namespace hdmap
}  // namespace apollo

#endif  // MODULES_MAP_HDMAP_ADAPTER_OPENDRIVE_ADAPTER_H_
